package com.lx.javasunmmrize.SingletonDemo;

/**
 * @Description 懒汉式（线程不安全）
 * <p>
 * 优点：可以实现懒加载
 * 缺点：只能在单线程情况下加载，在实际开发中不建议使用
 * @Author lx
 * @Date 2021/2/23 22:12
 **/
public class Singleton03 {

    public static void main(String[] args) {
        Sington03 instanc = Sington03.getInstance();
        Sington03 instanc2 = Sington03.getInstance();
        System.out.println(instanc == instanc2);
        System.out.println(instanc.hashCode());
        System.out.println(instanc2.hashCode());
    }
}

class Sington03 {
    private static Sington03 instance;

    private Sington03() {

    }

    public static Sington03 getInstance() {
        if (instance == null) {
            instance = new Sington03();
        }
        return instance;
    }

}